"use strict";
cc._RF.push(module, 'ab4abBEQj5JUozDeJ60B/QZ', 'HeroCardViewUI');
// scripts/HeroCardViewUI.js

"use strict";

var e = require;
var t = module;
var o = exports;

var _ii,
    nn = void 0 && (void 0).__extends || (_ii = function ii(t, e) {
  return (_ii = Object.setPrototypeOf || {
    __proto__: []
  } instanceof Array && function (t, e) {
    t.__proto__ = e;
  } || function (t, e) {
    for (var o in e) {
      Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
    }
  })(t, e);
}, function (t, e) {
  function o() {
    this.constructor = t;
  }

  _ii(t, e), t.prototype = null === e ? Object.create(e) : (o.prototype = e.prototype, new o());
}),
    rr = void 0 && (void 0).__awaiter || function (t, e, o, i) {
  return new (o || (o = Promise))(function (n, a) {
    function r(t) {
      try {
        l(i.next(t));
      } catch (e) {
        a(e);
      }
    }

    function s(t) {
      try {
        l(i["throw"](t));
      } catch (e) {
        a(e);
      }
    }

    function l(t) {
      var e;
      t.done ? n(t.value) : (e = t.value, e instanceof o ? e : new o(function (t) {
        t(e);
      })).then(r, s);
    }

    l((i = i.apply(t, e || [])).next());
  });
};

var oo = void 0 && (void 0).__decorate || function (e, t, a, n) {
  var i,
      o = arguments.length,
      s = o < 3 ? t : null === n ? n = Object.getOwnPropertyDescriptor(t, a) : n;
  if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) s = Reflect.decorate(e, t, a, n);else for (var r = e.length - 1; r >= 0; r--) {
    (i = e[r]) && (s = (o < 3 ? i(s) : o > 3 ? i(t, a, s) : i(t, a)) || s);
  }
  return o > 3 && s && Object.defineProperty(t, a, s), s;
};

Object.defineProperty(o, "__esModule", {
  value: !0
});

var a = e("BaseModuleUI"),
    n = e("NotifyEventType"),
    i = e("GlobalParams"),
    r = e("AssetsManager"),
    s = e("AudioManager"),
    l = e("Game"),
    _ = e("RoleSoldierInfo"),
    c = e("shop_role_item_node"),
    d = e("sdkConfig"),
    h = e("AD"),
    u = e("Toast"),
    p = e("Ad_Icon"),
    m = e("ActivityViewUI"),
    f = e("GetZsViewUI"),
    v = e("HeroInfoViewUI"),
    g = cc._decorator,
    y = g.ccclass,
    I = g.property,
    w = function (e) {
  function t() {
    var t = null !== e && e.apply(this, arguments) || this;
    return t.role_content_node = null, t.role_node_item = null, t.role_scroll_view = null, t.hero_type_list = [], t.choose_hero_name_sprite = null, t.choose_hero_skeleton = null, t.get_term = null, t.buy_btn_node = null, t.show_btn_node = null, t.native_icon = null, t.GameHeroList = [], t.choose_hero_index = 0, t;
  }

  return nn(t, e), t.prototype.initView = function () {
    e.prototype.initView.call(this), this.native_icon.active = d["default"].platform == d.EPlatform.OPPO && !h["default"].getInstance().getGameTestVersion(), this.showHeroInfo();
  }, t.prototype.addEvent = function () {
    this.attachEvent(n["default"].SEND_CHOOSE_ROLE_INDEX_INFO, this.showChooseHeroInfo, this);
  }, t.prototype.OnClick = function (t) {
    var o = this;
    e.prototype.OnClick.call(this, t);
    var a = t.node.name,
        r = i.GlobalParams.playerSkinInfo.value;

    switch (a) {
      case "all_hero_btn":
        this.showRoleType("all");
        break;

      case "far_hero_btn":
        this.showRoleType("far");
        break;

      case "near_hero_btn":
        this.showRoleType("near");
        break;

      case "buy_btn":
        if (d["default"].platform == d.EPlatform.OPPO && h["default"].getInstance().getNativeImageErrorControl()) return void this.native_icon.getComponent(p["default"]).nativeClick();
        var _ = l["default"].shop_role_info[this.choose_hero_index],
            c = i.GlobalParams.PlayerInfo.value;

        if (_.type < 2) {
          if (0 == _.type) {
            if (c.coin < _.num) return void u["default"].showNewToast("金币不足");
            this.uiManager.addCoinNum(-1 * _.num), r.have_hero.push(this.choose_hero_index), r.use[0] = this.choose_hero_index;
          } else c.zs < _.num ? this.uiManager.showPopup("GetZsViewUI", function (e) {
            e.getComponent(f["default"]).showPopupInfoView(0);
          }) : (this.uiManager.addZsNum(-1 * _.num), r.have_hero.push(this.choose_hero_index), r.use[0] = this.choose_hero_index);

          i.GlobalParams.PlayerInfo.value = c, i.GlobalParams.playerSkinInfo.value = r, this.emitEvent(n["default"].SEND_UPDATE_MY_USE_HORE_INFO), this.showHeroInfo();
        } else 2 == _.type ? this.uiManager.showPopup("ActivityViewUI", function (e) {
          e.getComponent(m["default"]).showActivityView(1);
        }) : 3 == _.type ? this.uiManager.showPopup("ActivityViewUI", function (e) {
          e.getComponent(m["default"]).showActivityView(0);
        }) : 4 == _.type ? h["default"].getInstance().showVideo(function (e) {
          s["default"].playGameBGM(), e == h.ResultEnum.Success && (r.have_hero.push(o.choose_hero_index), r.use[0] = o.choose_hero_index, i.GlobalParams.PlayerInfo.value = c, i.GlobalParams.playerSkinInfo.value = r, o.emitEvent(n["default"].SEND_UPDATE_MY_USE_HORE_INFO), o.showHeroInfo());
        }) : 5 == _.type && this.uiManager.showPopup("StoreHouseViewUI");

        break;

      case "show_btn":
        d["default"].platform == d.EPlatform.OPPO && h["default"].getInstance().getNativeImageErrorControl() ? this.native_icon.getComponent(p["default"]).nativeClick() : (r.use[0] = this.choose_hero_index, i.GlobalParams.playerSkinInfo.value = r, this.showChooseHeroInfo("", this.choose_hero_index), this.emitEvent(n["default"].SEND_UPDATE_MY_USE_HORE_INFO));
        break;

      case "hore_details_btn":
        this.uiManager.showPopup("HeroInfoViewUI", function (e) {
          e.getComponent(v["default"]).showHeroInfo(o.choose_hero_index);
        });
    }
  }, t.prototype.showHeroInfo = function () {
    this.GameHeroList = [];
    var e = _["default"].Role_info,
        t = i.GlobalParams.playerSkinInfo.value,
        o = [],
        a = [];
    i.GlobalParams.TryNewHero && this.GameHeroList.push(i.GlobalParams.NewHeroId);

    for (var n = 0; n < i.GlobalParams.GameHeroIndex.length; n++) {
      var r = i.GlobalParams.GameHeroIndex[n];
      -1 == t.have_hero.indexOf(r) ? a.push(r) : -1 == this.GameHeroList.indexOf(r) && o.push(r);
    }

    for (this.GameHeroList = this.GameHeroList.concat(o).concat(a), n = 0; n < this.GameHeroList.length; n++) {
      r = this.GameHeroList[n];
      var s = null;
      this.role_content_node.children[n] ? s = this.role_content_node.children[n] : (s = cc.instantiate(this.role_node_item)).setParent(this.role_content_node), s.active = !0, s.getComponent(c["default"]).showRoleInfo(e[r], r), t.use[0] == r && this.showChooseHeroInfo("", r);
    }
  }, t.prototype.showRoleType = function (e) {
    this.hero_type_list[0].active = "all" == e, this.hero_type_list[1].active = "far" == e, this.hero_type_list[2].active = "near" == e, this.role_scroll_view.scrollToTop(0.1);

    for (var t = 0, o = this.role_content_node.children; t < o.length; t++) {
      o[t].getComponent(c["default"]).showItemType(e);
    }
  }, t.prototype.showChooseHeroInfo = function (e, t) {
    var o = this,
        a = t;
    this.choose_hero_index = a;
    var n = i.GlobalParams.playerSkinInfo.value,
        s = _["default"].Role_info[a],
        c = l["default"].shop_role_info[a];
    this.choose_hero_name_sprite.spriteFrame = r["default"].getInstance().getHeroHeadFrame("hero_name_" + s.id), this.uiManager.getRoleSkele(s.id, function (e) {
      o.choose_hero_skeleton.skeletonData = e, o.choose_hero_skeleton.setAnimation(0, "battle_idle", !0);
    }), this.show_btn_node.parent.active = -1 != n.have_hero.indexOf(a), this.show_btn_node.getComponent(cc.Button).interactable = n.use[0] != a, this.show_btn_node.children[0].active = n.use[0] != a, this.show_btn_node.children[1].active = n.use[0] == a, this.buy_btn_node.parent.active = -1 == n.have_hero.indexOf(a), this.get_term.active = -1 == n.have_hero.indexOf(a);

    for (var d = 0; d < this.get_term.childrenCount; d++) {
      this.get_term.children[d].active = d == c.type, d < 2 && c.type < 2 && (this.get_term.children[d].children[1].getComponent(cc.Label).string = "x " + c.num);
    }

    this.buy_btn_node.active && (this.buy_btn_node.children[0].active = -1 != [0, 1].indexOf(c.type), this.buy_btn_node.children[1].active = -1 != [2, 3, 4, 5].indexOf(c.type), this.buy_btn_node.children[1].children[1].active = 4 == c.type);
  }, oo([I(cc.Node)], t.prototype, "role_content_node", void 0), oo([I(cc.Node)], t.prototype, "role_node_item", void 0), oo([I(cc.ScrollView)], t.prototype, "role_scroll_view", void 0), oo([I(cc.Node)], t.prototype, "hero_type_list", void 0), oo([I(cc.Sprite)], t.prototype, "choose_hero_name_sprite", void 0), oo([I(sp.Skeleton)], t.prototype, "choose_hero_skeleton", void 0), oo([I(cc.Node)], t.prototype, "get_term", void 0), oo([I(cc.Node)], t.prototype, "buy_btn_node", void 0), oo([I(cc.Node)], t.prototype, "show_btn_node", void 0), oo([I(cc.Node)], t.prototype, "native_icon", void 0), oo([y], t);
}(a["default"]);

o["default"] = w;

cc._RF.pop();